<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html style="height:100%">
    <head>
        <title>${comment}管理</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" type="text/css" href="/${project}/resource/js/easyui/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="/${project}/resource/js/easyui/themes/icon.css">
        <link rel="stylesheet" type="text/css" href="/${project}/resource/js/easyui/themes/color.css">

        
        <script src="/${project}/resource/js/easyui/jquery.min.js" type="text/javascript"></script>
        <script src="/${project}/resource/js/easyui/jquery.easyui.min.js" type="text/javascript"></script>
       <!-- <script src="../resource/js/easyui/easyloader.js" type="text/javascript"></script>-->   
        <script src="/${project}/resource/js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
        <script src="/${project}/resource/js/common.js" type="text/javascript"></script>
     
     
        <style type="text/css">
            #fm{
                margin:0;
                padding:10px 30px;
            }
            .ftitle{
                font-size:14px;
                font-weight:bold;
                padding:5px 0;
                margin-bottom:10px;
                border-bottom:1px solid #ccc;
            }
            .fitem{
                margin-bottom:5px;
            }
            .fitem label{
                display:inline-block;
                width:80px;
            }
            .fitem input{
                width:160px;
            }
        </style>

        <script type="text/javascript" >
            
            /*
             查询函数
            */
            function  query(){

                
                var params ="";

               <?py if extend != "":?>
               <?py    properties=models[extend]["properties"] + properties?>
   
               <?py #endif?>
                
               <?py for property in properties: ?>
                
                           
               

               <?py    if   property["inSearch"]:?>
               <?py     if property["dataType"] in baseDataTypes and property["dataType"] not in ["List"]:?>
                            var ${property["name"]} = $('#q${property["name"]}').textbox("getValue") ;
                            if(${property["name"]} && ${property["name"]} !== ""){
                                params += '&${property["name"]}='+${property["name"]};
                            }
                            
               <?py     elif property["dataType"] in ["List"]:?>
                            var ${property["name"]} = $('#q${property["name"]}').combobox("getValue") ;
                             if(${property["name"]} && ${property["name"]} !== ""){
                                params += '&${property["name"]}[0].id='+${property["name"]};
                             }
               <?py     else:?>
                            var ${property["name"]} = $('#q${property["name"]}').combobox("getValue") ;
                             if(${property["name"]} && ${property["name"]} !== ""){
                                params += '&${property["name"]}.id='+${property["name"]};
                             }
                            
               <?py     #endif ?>    
               <?py    #endif ?> 
              
               <?py #endfor     ?>

               <?py if isTree(name):?>
                  $('#dg').treegrid({url: '/${project}/api/${name}?id='+params, method: 'get'});

                  $('#dg').treegrid('reload');
               
               <?py else:?>
                 $('#dg').datagrid({url: '/${project}/api/${name}?id='+params, method: 'get'});

                 $('#dg').datagrid('reload');

               <?py #endif ?>
            }
            
            
            
            function new${upperFirst(name)}() {
                
                $('#dlg').dialog('open').dialog('setTitle', '新建${comment}');
                $('#fm').form('clear');
                
                url = '/${project}/api/${name}';

               <?py for property in properties:?>
               <?py    if property["dataType"] == "List":?>

                 $.get('/${project}/api/${property["elementType"]}/all',function(data){
                    $('#${property["name"]}').empty();
                    for(var i=0;i<data.length;i++){
                        var id = data[i].id;
                        var name = data[i].name;
                        $('#${property["name"]}').append("<label><input type='checkbox' name='${property["name"]}["+i+"].id' value='"+id+"'/>"+name+"</label>");
                    }
                });
               <?py    elif property["dataType"] not in  baseDataTypes:?>
               <?py     if isTree(property["dataType"]):?>
                            
                            $.get('/${project}/api/${property["dataType"]}/all',function(data){

                                
                                
                                 $('#${property["name"]}').combotree('loadData', convertToTree(data,null));
                             });
               <?py     else:?>
                           $('#${property["name"]}').combobox("reload");
               <?py     #endif?>            
               <?py    #endif  ?>
               <?py #endfor     ?>
            }

            function save${upperFirst(name)}() {
                $('#fm').form('submit', {
                    url: url,
                    method:'post',
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        var result = eval('(' + result + ')');
                        if (!result.success) {
                            $.messager.show({
                                title: '出错',
                                msg: result.msg
                            });
                        } else {
                            $('#dlg').dialog('close');        // close the dialog
               <?py if isTree(name):?>
                  
                  $('#dg').treegrid('reload');// reload the user data
               
               <?py else:?>
                 

                 $('#dg').datagrid('reload');// reload the user data

               <?py #endif ?>                            


                              
                        }
                    }
                });
            }

            function edit${upperFirst(name)}() {

                var row = $('#dg').datagrid('getSelected');
                if (row) {
                    $('#dlg').dialog('open').dialog('setTitle', '编辑${comment}');
                    $('#fm').form('load', row);
                   url = '/${project}/api/${name}/' + row.id+'?_method=PUT';


               <?py for property in properties:?>
               <?py    if property["dataType"] == "List":?>

                 $.get('/${project}/api/${property["elementType"]}/all',function(data){
                    $('#${property["name"]}').empty();
                    for(var i=0;i<data.length;i++){
                        var id = data[i].id;
                        var name = data[i].name;

                        var tt;
                        for(var j=0;j<row.${property["name"]}.length;j++){
                            if(row.${property["name"]}[j] && row.${property["name"]}[j].id ===id){
                                tt="checked";
                                break;
                            }else {
                                tt = "";
                            }
                        }
                        $('#${property["name"]}').append("<label><input type='checkbox'"+tt+" name='${property["name"]}["+i+"].id' value='"+id+"'/>"+name+"</label>");
                    }
                });

               <?py    elif property["dataType"] not in  baseDataTypes:?> 
               <?py     if isTree(property["dataType"]):?>
                       
                        $.get('/${project}/api/${property["dataType"]}/all',function(data){

                                
                                
                                 $('#${property["name"]}').combotree('loadData', convertToTree(data,null));
                                 $('#${property["name"]}').combotree('setValue',row.${property["name"]}.id);
                             });
                         
               <?py     else:?>
                        $('#${property["name"]}').combobox("reload");
                        $('#${property["name"]}').combobox('setValue',row.${property["name"]}.id); 
               <?py     #endif  ?>         
               <?py    #endif  ?>
               <?py #endfor     ?>

                   
                      
                   
                }
            }

            function destroy${upperFirst(name)}() {
                var row = $('#dg').datagrid('getSelected');
                if (row) {
                    
                                        
                    $.messager.confirm('确认提示', '你确定要删除此${comment}吗?', function (r) {
                        if (r) {
                            $.post('/${project}/api/${name}/' + row.id, {'_method':'DELETE'}, function (result) {
                                if (result.success) {

               <?py if isTree(name):?>
                  
                  $('#dg').treegrid('reload');// reload the user data
               
               <?py else:?>
                 

                 $('#dg').datagrid('reload');// reload the user data

               <?py #endif ?>                                      
                                } else {
                                    $.messager.show({// show error message
                                        title: '删除失败',
                                        msg: result.msg,
                                        icon:'error'
                                    });
                                }
                            }, 'json');
                        }
                    });
                }
            }
           
                <?py for property in properties:?>

                
                <?py    if property["dataType"] not in baseDataTypes:?>
                
                    function  format${property["name"].capitalize()}(value,rec){
               
                        if(rec.${property["name"]}){
                            return rec.${property["name"]}.name; 
                        }
               
           
                    }
                <?py    elif property["dataType"] =="List":?>

                     function  format${property["name"].capitalize()}(value,rec){
               
                        if(rec.${property["name"]}&&rec.${property["name"]}.length>0){
                            
                            var str="";
                            for(var i=0;i<rec.${property["name"]}.length;i++){
                             
                             str += rec.${property["name"]}[i].name+",";
                             
                            }
                           return str.substr(0,str.length-1);
                        }
                         
                         
                     }
           
                    

                <?py    #endif  ?>
                <?py #endfor     ?>           
       
          
        </script>
    </head>
    <body style="height:100%">
                <?py if isTree(name):?>

            <table id="dg" title="${comment}信息" class="easyui-treegrid" style="width:100%;height:100%"
               
               data-options="url:'/${project}/api/${name}',method:'get', idField:'id', treeField :'name',
                loadFilter: treeGridFilter,toolbar:'#toolbar',
                rownumbers:true,pagination:true,fitColumns:true,singleSelect:true">

                <?py else:?>


        <table id="dg" title="${comment}信息" class="easyui-datagrid" style="width:100%;height:540px"
               url="/${project}/api/${name}" method="get"
               toolbar="#toolbar"  pagination="true" 
               rownumbers="true" fitColumns="true" singleSelect="true">
               <?py #endif?>
            <thead>
                <tr>
                    <th field="id" width="50" hidden="true">ID</th>
                <?py for property in properties:?>  
                <?py    if   property["inTable"]:?>
                <?py        if property["dataType"] not in baseDataTypes:?>   
                    <th field="${property["name"]}"  data-options="sortable:true, formatter:format${property["name"].capitalize()}"> ${property["comment"]}</th>
                <?py        elif property["dataType"] == "List":?>
                      <th field="${property["name"]}"  data-options="sortable:true, formatter:format${property["name"].capitalize()}"> ${property["comment"]}</th>

                <?py        else:?>
                    <th field="${property["name"]}"  data-options="sortable:true"> ${property["comment"]}</th> 
                <?py        #endif  ?>   
                <?py    #endif  ?>   
                <?py #endfor     ?>    

                </tr>
            </thead>
        </table>

        <div id="toolbar">
            <!--  查询条件选择区 -->
                


                <?py for property in properties:?> 
                <?py    if   property["inSearch"]:?>

                <label>${property["comment"]}:</label> 
                    
                <?py        if property["dataType"] not in baseDataTypes:?> 

                <?py            if isTree(property["dataType"]):?>
                             <input  id="q${property["name"]}" name="${property["name"]}.id" style="width:150px;">

                <?py            else:?>

                    <input  id="q${property["name"]}" name="${property["name"]}.id" class="easyui-combobox"    style="width:80px;" data-options="
                     url:'/${project}/api/${property["dataType"]}/all',
                    method:'get',
                    panelHeight:'auto',        
                    valueField: 'id',
                    textField: 'name',
                    
                    ">
                <?py            #endif?>

                <?py        elif property["dataType"] in ["Set","List"]:?>

                <?py            if isTree(property["elementType"]):?>
                             <input  id="q${property["name"]}" name="${property["name"]}.id" style="width:150px;">

                <?py            else:?>


                           <input  id="q${property["name"]}" name="${property["name"]}.id" class="easyui-combobox"    style="width:80px;" data-options="
                     url:'/${project}/api/${property["elementType"]}/all',
                    method:'get',
                    panelHeight:'auto',        
                    valueField: 'id',
                    textField: 'name',
                    
                    ">
                <?py            #endif?>

                <?py        else:?>
                    <input  id="q${property["name"]}" name="${property["name"]}" class="easyui-textbox"    style="width:80px;">
                <?py        #endif  ?>  
                <?py    #endif ?> 

                <?py #endfor     ?>

            
                
                
                
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="query()">查询</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="new${upperFirst(name)}()">新建</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit${upperFirst(name)}()">编辑</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroy${upperFirst(name)}()">删除</a>
        </div>

        <!--  编辑 对话框 -->      
        <div id="dlg" class="easyui-dialog" style="width:700px;height:450px;padding:10px 20px"
             closed="true" buttons="#dlg-buttons">
            <div class="ftitle">${comment}信息编辑</div>
            <form id="fm" method="post">

                <?py tag=1  ?>
                <?py v="left"  ?>

                <?py for property in properties:?> 
                <?py    if tag%2 == 0:?> 
                <?py        v="right" ?> 
                <?py    else:?>
                <?py        v="left"  ?>
                <?py    #endif  ?>
                    
                    
                <?py    if property["dataType"] not in baseDataTypes:?> 
                    <div class="fitem" style="float:${v}">
                     <label>${property["comment"]}:</label> 
                <?py        if isTree(property["dataType"]):?>
                             <input  id="${property["name"]}" name="${property["name"]}.id" style="width:150px;">

                <?py        else:?>
                    <input  id="${property["name"]}" name="${property["name"]}.id" class="easyui-combobox"  class="fitem"   data-options="
                     url:'/${project}/api/${property["dataType"]}/all',
                    method:'get',
                    panelHeight:'auto',        
                    valueField: 'id',
                    textField: 'name',
                    
                    ">
                <?py        #endif?>
                    </div>
                <?py    elif property["dataType"] == "Date":?>
                  <div class="fitem" style="float:${v}">
                    <label>${property["comment"]}:</label>
                    <input name="${property["name"]}" class="easyui-datebox" >
                  </div>

                <?py    elif property["dataType"] in ["int","float","double"]: ?>
                   <div class="fitem" style="float:${v}">
                    <label>${property["comment"]}:</label>
                    <input name="${property["name"]}" class="easyui-numberbox" >
                   </div>
                <?py    elif property["dataType"] in ["Set","List"]: ?>
                   <div  style="width:100%;float:left">
                    <label>${property["comment"]}:</label>
                <?py        if isTree(property["elementType"]):?>
                             <input  id="${property["name"]}" name="${property["name"]}.id" style="width:150px;">

                <?py        else:?>    
                    <span  id="${property["name"]}"     style="margin: 0px;padding: 0px"></span>
                   </div>
                <?py        #endif?>   

                <?py    else:?>
                <?py        if property["ui"] == "textarea":?>
                    <div class="fitem" style="float:left;">
                    <label>${property["comment"]}:</label>
                    
                    <input name="${property["name"]}" class="easyui-textbox" data-options="multiline:true" style="width:100%;height:100px"> 
                    <?py        elif property["ui"] == "password":?>
                    <div class="fitem" style="float:${v}">
                    <label>${property["comment"]}:</label>
                    
                    <input name="${property["name"]}" class="easyui-passwordbox" > 
                    <?py        else:?>
                    <div class="fitem" style="float:${v}">
                    <label>${property["comment"]}:</label>
                    
                    <input name="${property["name"]}" class="easyui-textbox"  >
                    <?py        #endif?>
                    </div>
               
                <?py    #endif?>  
                <?py    tag += 1  ?>  
                <?py #endfor     ?>



            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="save${upperFirst(name)}()">保存</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
        </div>


    <script>

                <?py for property in properties:?> 
                <?py    if   property["inSearch"]:?>
                    
                <?py        if property["dataType"] not in baseDataTypes:?> 

                <?py            if isTree(property["dataType"]):?>

                             $.get('/${project}/api/${property["dataType"]}/all',function(data){

                                 $('#q${property["name"]}').combotree({editable:true});
                                 $('#q${property["name"]}').combotree('loadData', convertToTree(data,null));
                                 $('#${property["name"]}').combotree({editable:true});
                                 $('#${property["name"]}').combotree('loadData', convertToTree(data,null));
                             });
               
                <?py            #endif?>

                <?py        elif property["dataType"] in ["Set","List"]:?>

                <?py            if isTree(property["elementType"]):?>
                          $.get('/${project}/api/${property["elementType"]}/all',function(data){
                            $('#q${property["name"]}').combotree({checkbox:true,editable:true});
                             
                            $('#q${property["name"]}').combotree('loadData', convertToTree(data,null));

                            $('#${property["name"]}').combotree({checkbox:true,,editable:true});
                            $('#${property["name"]}').combotree('loadData', convertToTree(data,null));
                        });
               
                <?py            #endif?>
                    <?py    #endif ?> 
                
                <?py    #endif ?> 

                <?py #endfor     ?>

    </script>
    </body>
</html>
